package com.example.yiwei.crm.view.activity.JYCoordingActivity;

import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.ContextThemeWrapper;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.yiwei.crm.R;
import com.example.yiwei.crm.base.baseClass;
import com.example.yiwei.crm.data.GetAppointment;
import com.example.yiwei.crm.entity.ApointmentEntity;
import com.example.yiwei.crm.util.NetWorkUtils;
import com.example.yiwei.crm.view.activity.customerActivity.CoorCustomerDetailedApoActivity;
import com.example.yiwei.crm.view.activity.jtCustomer.JDcoorActivity;

import org.json.JSONException;
import org.json.JSONObject;


public class JYCoordDetailedAppointActivity extends AppCompatActivity {
    private TextView txt_name,txt_hospital,txt_department,txt_doctor,txt_state,txt_disease,txt_reason,txt_appointment_number,
            txt_appointment_time,txt_way_to_hospital,txt_time_to_hospital,txt_jb,txt_yyr,txt_cjr,txt_ctime,txt_jz_time;
    private ImageView img_delete,img_update,img_back;
    ApointmentEntity apointmentEntity;
    AlertDialog.Builder builder;
    String customer_name;
    String result;
    private ImageView img_luru,img_find,img_tj,img_me;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_jycoord_detailed_appoint);
        img_back= (ImageView) findViewById(R.id.detailed_doc_img_back);
        img_luru= (ImageView) findViewById(R.id.item_image_lr);
        img_find= (ImageView) findViewById(R.id.item_image_cx);
        img_me= (ImageView) findViewById(R.id.item_image_w);
        img_tj= (ImageView) findViewById(R.id.item_image_tj);
        txt_name= (TextView) findViewById(R.id.customer_appointment_txt_name);
        txt_hospital= (TextView) findViewById(R.id.customer_appointment_txt_hospital);
        txt_jz_time = (TextView) findViewById(R.id.customer_appointment_txt_jz_time);
        txt_department= (TextView) findViewById(R.id.customer_appointment_txt_department);
        txt_doctor= (TextView) findViewById(R.id.customer_appointment_txt_doctor);
        txt_disease= (TextView) findViewById(R.id.customer_appointment_txt_disease);
        txt_jb = (TextView) findViewById(R.id.customer_appointment_txt_jibing);
        txt_state= (TextView) findViewById(R.id.customer_appointment_txt_state);
        txt_reason= (TextView) findViewById(R.id.customer_appointment_txt_reason);
        txt_appointment_number= (TextView) findViewById(R.id.customer_appointment_txt_appointment_number);
        txt_appointment_time= (TextView) findViewById(R.id.customer_appointment_txt_time);
        txt_way_to_hospital= (TextView) findViewById(R.id.customer_appointment_txt_way_to_hospital);
        txt_time_to_hospital= (TextView) findViewById(R.id.customer_appointment_txt_time_to_hospital);
        img_delete= (ImageView) findViewById(R.id.detailed_doc_img_delete1);
//        txt_jdr = (TextView) findViewById(R.id.customer_appointment_txt_jd);
        txt_yyr= (TextView) findViewById(R.id.customer_appointment_txt_yuyueren);
        txt_cjr = (TextView) findViewById(R.id.customer_appointment_txt_cname);
        txt_ctime = (TextView) findViewById(R.id.customer_appointment_txt_ctime);
        img_update= (ImageView) findViewById(R.id.detailed_doc_img_update);
        apointmentEntity= GetAppointment.get();
        txt_jz_time.setText(apointmentEntity.getTriage_date());
        txt_name.setText(apointmentEntity.getCustomer_name());
        txt_hospital.setText(apointmentEntity.getAppoint_hospital());
        txt_department.setText(apointmentEntity.getAppint_department());
        txt_doctor.setText(apointmentEntity.getAppoint_doctor());
        txt_disease.setText(apointmentEntity.getDisease_category());
        txt_jb.setText(apointmentEntity.getDisease());
        txt_appointment_time.setText(apointmentEntity.getAppoint_date());
        txt_way_to_hospital.setText(apointmentEntity.getClue_channel_source());
        txt_time_to_hospital.setText(apointmentEntity.getClue_channel_classification());
        txt_yyr.setText(apointmentEntity.getYy_name());
//        txt_jdr.setText(apointmentEntity.getJd_name());
        txt_cjr.setText(apointmentEntity.getCurrent_create_name());
        txt_ctime.setText(apointmentEntity.getCreate_time());
        if (apointmentEntity.getAppointment_state()==0){
            txt_state.setText("预约");
        }else if (apointmentEntity.getAppointment_state()==1){
            txt_state.setText("初诊");
        }else if (apointmentEntity.getAppointment_state()==2){
            txt_state.setText("复诊");
        }
        img_update.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(JYCoordDetailedAppointActivity.this,JYAddApoActivity.class);
                intent.putExtra("TAG","updata");
                startActivity(intent);
                finish();
            }
        });
   img_back.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        finish();
    }
});
        img_tj.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(JYCoordDetailedAppointActivity.this, JDcoorActivity.class);
                intent.putExtra("tt","tt");
                startActivity(intent);
                finish();

            }
        });
        img_me.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(JYCoordDetailedAppointActivity.this, JDcoorActivity.class);
                intent.putExtra("me","me");
                startActivity(intent);
                finish();
            }
        });
        img_luru.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(JYCoordDetailedAppointActivity.this, JDcoorActivity.class);
                startActivity(intent);
                finish();
            }
        });
        img_find.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(JYCoordDetailedAppointActivity.this, JDcoorActivity.class);
                intent.putExtra("ii","ii");
                startActivity(intent);
                finish();
            }
        });
        txt_reason.setText(apointmentEntity.getAppoint_additional());
        txt_appointment_number.setText(apointmentEntity.getAppointment_number());
        img_delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                builder = new AlertDialog.Builder(new ContextThemeWrapper(JYCoordDetailedAppointActivity.this, R.style.custom_dialog));
                builder.setTitle("您确定要删除吗？");
                builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        new Thread(new Runnable() {
                            @Override
                            public void run() {
                                final JSONObject object = new JSONObject();
                                try {
                                    object.put("DEL01",1);
                                    object.put("KYA01",apointmentEntity.getAppoint_id());
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                                String json = object.toString();
                                result= NetWorkUtils.getCount(baseClass.delect_coor_yu_URL,json);
                                runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        try {
                                            JSONObject object1 = new JSONObject(result);
                                            boolean b = object1.getBoolean("ifsuccess");
                                            if (b){
                                                finish();
                                            }
                                        } catch (JSONException e) {
                                            e.printStackTrace();
                                        }

                                    }
                                });

                            }
                        }).start();
                    }
                });
                builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {

                    }
                });
                builder.show();

            }
        });

    }

}
